<style>
    #shellPrice{
        display: none;
    }
    .shell-site-table{
        overflow-y: auto;
    }
    .local-table{
        width: 100%;
        border: none;
    }
    .local-table thead {
        background: #fafafa;
    }
    .local-table thead th{
        min-width: 100px;
        padding: 9px 0;
    }
    .local-table td{
        text-align: center;
    }
    .local-table td input[type=text]{
        text-align: center;
        width: 60px;
        height: 30px;
        margin: 5px;
        border: 1px solid #e3e3e3;
        border-radius: 5px;
    }
    #shellPrice table tbody tr td:nth-child(n+4) div{
        border: 1px solid #e5e5e5;
        margin: 0 1px;
        text-align: center;
    }
    #shellPrice table tbody tr td:nth-child(n+9) div{
        border: none;
        margin: 0;
        text-align: center;
    }
    #shellPrice table tbody tr td .layui-table-cell{
        height: 100%;
        min-height: 28px;
    }
    #imgUrlAddress{
        width: 600px;
    }
</style>
<div class="layui-fluid layui-anim febs-anim" id="febs-activity" lay-title="市场活动调查">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="activity-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">油站名称</label>
                                        <div class="layui-input-inline">
                                            <select id="siteSelect" lay-filter="siteFilter" name="shellSite" lay-verify="required" lay-search="">
                                                <option value=""></option>
                                            </select>
                                        </div>
                                        <label class="layui-form-label layui-form-label-sm">日期</label>
                                        <div class="layui-input-inline">
                                            <input type="text" class="layui-input" name="searchDate" id="searchDate" placeholder="yyyy-MM-dd">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">价格类别调查</label>
                                    <div class="layui-input-block">
                                        <!--<input type="radio" lay-filter="typeRadio" name="radioType" value="0" title="价格调查" checked>-->
                                        <input type="radio" lay-filter="typeRadio" name="radioType" value="1" title="市场促销" checked>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button type="button" class="layui-btn" id="uploadImg">
                                            <i class="layui-icon">&#xe67c;</i>上传图片
                                        </button>
                                        <input id="imgUrlAddress" type="text" name="" placeholder="图片地址" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="dict:add,dict:update,dict:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <!--市场促销-->
                    <div id="shellMarket" class="shell-site-table">
                        <table id="tableMarket" lay-filter="activityTable" lay-data="{id: 'marketTable'}"></table>
                        <table id="tableAc" lay-filter="activityTable" lay-data="{id: 'tableAc'}">
                            <tbody>

                            </tbody>
                        </table>
                        <!--市场促销-内容列表-壳牌-->
                        <table id="tableMarketList" lay-filter="activityTable" lay-data="{id: 'tableMarketList'}"></table>
                        <table id="tableMarketCom" lay-filter="activityTable" lay-data="{id: 'marketComTable'}"></table>
                        <table id="tableBc" lay-filter="activityTable" lay-data="{id: 'tableBc'}">
                            <tbody>

                            </tbody>
                        </table>
                        <!--市场促销-内容列表-竞争对手-->
                        <table id="tableMarketListCom" lay-filter="activityTable" lay-data="{id: 'tableMarketListCom'}"></table>
                    </div>
                    <!--价格调查-->
                    <div id="shellPrice">
                        <table id="tablePrice" lay-filter="activityTable" lay-data="{id: 'activityTable'}"></table>
                        <!--价格调查-内容列表-壳牌-->
                        <table id="tablePriceList" lay-filter="activityTable" lay-data="{id: 'tablePriceList'}"></table>

                        <table id="tableCompetitors" lay-filter="activityTable" lay-data="{id: 'competitorsTable'}"></table>
                        <!--市场促销-内容列表-竞争对手-->
                        <!--<table id="tablePriceCompetitors" lay-filter="activityTable" lay-data="{id: 'tablePriceCompetitors'}"></table>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--壳牌表格头部-->
<script type="text/html" id="toolbarDemo">
    <label class="layui-form-label">壳牌油站</label>
</script>
<!--竞争对手表格头部-->
<script type="text/html" id="toolbarDemoC">
    <label style="width: 200px;text-align: left;" class="layui-form-label">竞争对手油站</label>
</script>
<script type="text/html" id="dict-option">
    <span shiro:lacksPermission="shellActivity:view,shellActivityPrice:save">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <span shiro:hasPermission="shellActivityPrice:save"><button lay-event="save" type="button" class="layui-btn layui-btn-xs">保存</button></span>
</script>
<!--market-->
<script type="text/html" id="dict-option-market">
    <span shiro:lacksPermission="shellActivity:view,shellActivityPrice:save">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <span shiro:hasPermission="shellActivityPrice:save"><button lay-event="save" type="button" class="layui-btn layui-btn-xs">保存</button></span>
    <span class="btnShowInfo"><button lay-event="info" type="button" class="layui-btn layui-btn-xs">促销详情</button></span>
</script>
<!--删除-->
<script type="text/html" id="actDel">
    <div>
        <button type="button" class="layui-btn layui-btn-xs">删除</button>
    </div>
</script>
<!--img-->
<script type="text/html" id="imgTpl">
    <div>
        <button type="button" class="layui-btn layui-btn-xs" id="imgView">查看</button>
    </div>
</script>
<!--0号-->
<script type="text/html" id="oliZero">
    <div>
        <button type="button" class="layui-btn layui-btn-xs" id="">
            <i class="layui-icon">&#xe654;</i>
        </button>
    </div>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'util','table', 'febs', 'formSelects', 'upload'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            util=layui.util,
            table = layui.table,
            dropdown = layui.dropdown,
            formSelects = layui.formSelects,
            upload = layui.upload,
            $view = $('#febs-activity'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'fromDate', type: null},
            tableIns,
            tableInsCom,
            tableInsPrice,
            tableInsPriceCom,
            tableInsMarket,
            tableInsMarketCom,
            tableInsMarketList,
            tableInsMarketListCom,
            listContent = [],
            listContentCom = [],
            listPrice = [],
            listPriceCom = [],
            firstLoad = true,
            siteType='1',
            oliZeroTemp = '',
            shellActivityOilDetailList = localStorage.getItem('ShellActivityOilDetail');
        var activityZyData = [],
            activityJzData = [];
        //select请求
        activityJzSelect();
        activityZySelect();

        form.render();
        initDataSite();

        //常规用法
        laydate.render({
            elem: '#searchDate'
        });


        laydate.render({
            elem: '#fromDate',
            type: 'datetime',
            format:'yyyy-MM-dd',
            range: true,
            trigger: 'click'
        });

        table.on('tool(activityTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event,
                tr = obj.tr;
            // 列表-日期修改
            if (layEvent === 'date') {
                var field = $(this).data('field');
                laydate.render({
                    elem: this.firstChild,
                    type: 'datetime',
                    format: "yyyy-MM-dd",
                    show: true , //直接显示
                    closeStop: this ,
                    done: function (value, date) {
                        data[field] = value;
                        obj.update(data);
                        // obj.update({
                        //     oilDate: value
                        // });
                    }
                })
            }
            // 列表-图片上传
            if (layEvent === 'img') {
                layer.open({
                    title: "图片查看",
                    content: '<image src="'+data.liveUrl+'"/>',
                    yes: function(index, layero){
                        //do something
                        layer.close(index); //如果设定了yes回调，需进行手工关闭
                    }
                });
            }
            if (layEvent === 'actDel') {
                // alert(data.id)
                //单条活动数据删除
                // var id=data.id;
                febs.post(ctx + 'shellActivity/shellActivityDetaiDel', {id:data.id}, function () {
                    febs.alert.success('操作成功');
                    $('#febs-activity').find('#query').click();
                });
            }
            // 保存
            if (layEvent === 'save') {
                var datailList = [], currentList = localStorage.getItem('ShellActivityOilDetail');
                if (currentList) {
                    datailList = JSON.parse(currentList);
                } else  {
                    alert("未添加数据保存");
                    return false;
                    // datailList = data.shellActivityOilDetailList
                }
                var remark = tr.next().find("textarea").val();
                var str = {
                    jsonPrice: [{
                        shellId: data.shellId,
                        shellCode: data.shellCode,
                        shellName: data.shellName,
                        oilDate: data.actDate,
                        shellActivityOilList: [
                            {
                                activityId: data.shellActivityOilList[0].activityId,
                                shellId: data.shellId,
                                oilCode: '#0',
                                price: data.oil0
                            },
                            {
                                activityId: data.shellActivityOilList[0].activityId,
                                shellId: data.shellId,
                                oilCode: '#92',
                                price: data.oil92
                            },

                            {
                                activityId: data.shellActivityOilList[0].activityId,
                                shellId: data.shellId,
                                oilCode: '#95',
                                price: data.oil95
                            },
                            {
                                activityId: data.shellActivityOilList[0].activityId,
                                shellId: data.shellId,
                                oilCode: '#98',
                                price: data.oil98
                            }
                        ],
                        shellActivityOilDetailList: datailList,
                        liveUrl: data.liveUrl,
                        type: data.type,
                        remark: remark
                    }]
                };
                var _str = JSON.stringify(str.jsonPrice);
                if (siteType == 0) {
                    febs.post(ctx + 'shellActivity/shellActivityPriceSave', {jsonPrice: _str}, function () {
                        febs.alert.success('保存成功');
                        $('#febs-activity').find('#query').click();
                    });
                } else {
                    febs.post(ctx + 'shellActivity/shellActivityDetailSave', {jsonPrice: _str}, function () {
                        febs.alert.success('保存成功');
                        $('#febs-activity').find('#query').click();
                        localStorage.setItem('ShellActivityOilDetail', '');
                        cleanShow();
                    });
                }

            }
            //添加 - 根据不用event判断品号不同
            if (layEvent === 'saleOil0') {
                // localStorage.setItem('ShellActivityOilDetail', '');
                // cleanShow();
                // var currentData = oilDataFormat(layEvent, data);
                var dataString = JSON.stringify(data);
                localStorage.setItem('activityVal', dataString);
                febs.modal.open('市场促销', '/activity/shellActivity/marketSale/' + 0, {
                    area: ['100%', '100%']
                });
            }
            if (layEvent === 'saleOil92') {
                // localStorage.setItem('ShellActivityOilDetail', '');
                // cleanShow();
                var dataString = JSON.stringify(data);
                localStorage.setItem('activityVal', dataString);
                febs.modal.open('市场促销', '/activity/shellActivity/marketSale/' + 92, {
                    area: ['100%', '100%']
                });
            }
            if (layEvent === 'saleOil95') {
                // cleanShow();
                // localStorage.setItem('ShellActivityOilDetail', '');
                // var currentData = oilDataFormat(layEvent, data);
                var dataString = JSON.stringify(data);
                localStorage.setItem('activityVal', dataString);
                febs.modal.open('市场促销', '/activity/shellActivity/marketSale/' + 95, {
                    area: ['100%', '100%']
                });
            }
            if (layEvent === 'saleOil98') {
                // localStorage.setItem('ShellActivityOilDetail', '');
                // cleanShow();
                // var currentData = oilDataFormat(layEvent, data);
                var dataString = JSON.stringify(data);
                localStorage.setItem('activityVal', dataString);
                febs.modal.open('市场促销', '/activity/shellActivity/marketSale/' + 98, {
                    area: ['100%', '100%']
                });
            }

        });
        //上传图片
        // $(document).on("click",'#uploadImg', function () {
        //
        // });
        upload.render({
            elem: '#uploadImg'
            ,url: ctx + 'uploadFile/file/price' //必填项
            ,accept:'images'
            ,acceptMime: 'image/jpg,image/png,image/jpeg'
            ,exts: 'jpg|png|jpeg'
            ,size: 2048
            ,field:"file"
            ,auto: true
            ,choose: function (obj) {
                console.log(obj)
            }
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                febs.view.loadBar.start();
                console.log('1')
            }
            ,done: function(res){
                febs.view.loadBar.finish();
                layer.msg("上传成功！");
                console.log(res, '图片上传');
                $('#imgUrlAddress').val(res.data);
            }
        });

        //搜索框
        $query.on('click', function () {
            localStorage.setItem('ShellActivityOilDetail', '');
            cleanShow();
            var params = $.extend(getQueryParams(), {});
            layer.load(2);
            if (!params.shellId){
                febs.alert.warn('油站不能为空');
                layer.close(layer.load(2));
                return false;
            }
            isMarketFunc();
            initTableMarket(params);
            initTableMarketCom(params);
            initTableMarketShow();
            initTableMarketComShow();
            if (siteType == 1) {
                if (firstLoad) {
                    // isMarketFunc();
                    // initTable(params);
                    // initTableC(params);
                    // initTableMarket(params);
                    // initTableMarketCom(params);
                    // initTableMarketShow();
                    // initTableMarketComShow();
                    // initTablePriceData();
                    // initTablePriceComData();
                    firstLoad = false

                } else {
                    // isMarketFunc();
                    tableInsMarket.reload({where: getQueryParams(), data: ajaxGet('shellActivity/shellOilAllList',params).list});
                    tableInsMarketCom.reload({where: getQueryParams(),data: ajaxGet('shellActivity/shellOilAllList',params).listC});
                    tableInsMarketList.reload({where: '', data: listContent});
                    tableInsMarketListCom.reload({where: '', data: listContentCom});
                    tableInsPrice.reload({where: '', data: listPrice});
                    tableInsPriceCom.reload({where: '', data: listPriceCom})
                }
            } else  {
                if (firstLoad) {
                    // isMarketFunc();
                    // initTable(params);
                    // initTableC(params);
                    // initTableMarket(params);
                    // initTableMarketCom(params);
                    // initTableMarketShow();
                    // initTableMarketComShow();
                    // initTableMarketComShow();
                    // initTablePriceData();
                    // initTablePriceComData();
                    firstLoad = false

                } else {
                    // isMarketFunc();
                    tableIns.reload({where: getQueryParams(), data: ajaxGet('shellActivity/shellOilAllList',params).list});
                    tableInsCom.reload({where: getQueryParams(),data: ajaxGet('shellActivity/shellOilAllList',params).listC});
                }
            }
        });
        //搜索框-清空
        $reset.on('click', function () {
            $searchForm[0].reset();
        });
        //类型判断-切换页面
        form.on('radio(typeRadio)', function(data){
            siteType = data.value;
            $('#febs-activity').find('#query').click();
        });
        form.on('select(siteFilter)', function (data) {
            $('#febs-activity').find('#query').click();
        });
        //改变编辑值
        // table.on('edit(activityTable)',function (obj) {
        //     //获取编辑前的值
        //     var selector = obj.tr.selector+' td[data-field="'+obj.field+'"] div';
        //     var oldtext = $(selector).text();
        //     //判断数据类型
        //     if(!isNumber(obj.value)) {
        //         layer.msg('请输入数字');
        //         console.log(oldtext);
        //         // 重点 赋值
        //         $(obj.tr.selector + ' td[data-field="' + obj.field + '"] input').val(oldtext);
        //     }
        // });
        //价格调查-壳牌
        // function initTable(params){
        //     // 活动
        //     tableIns = febs.table.init({
        //         elem: '#tablePrice',
        //         // url: ctx + 'shellActivity/shellOilAllList',
        //         toolbar: '#toolbarDemo',//开启头部工具栏，并为其绑定左侧模板
        //         defaultToolbar: [],
        //         where: params ? params : '',
        //         cols: [[
        //             {type: 'checkbox'},
        //             {field: 'shellName', title: '油站名称', minWidth: 200},
        //             {field: 'oilDate', title: '日期', minWidth: 200, event: 'date', data_field: "date"},
        //             {field: 'oil0', title: '0#柴油', minWidth: 50, edit: 'text'},
        //             {field: 'oil92', title: '92#汽油', minWidth: 50, edit: 'text'},
        //             {field: 'oil95', title: '95#汽油', minWidth: 50, edit: 'text'},
        //             {field: 'oil98', title: '98#汽油', minWidth: 50, edit: 'text'},
        //             {field: 'liveUrl', title: '图片地址', minWidth: 50, edit: 'text'},
        //             {field: '', title: '图片查看', minWidth: 50, event: 'img', templet:'#imgTpl'},
        //             {title: '操作', toolbar: '#dict-option', minWidth: 140},
        //         ]],
        //         page: false,
        //         data: ajaxGet('shellActivity/shellOilAllList',params,0).list,
        //         done: function (res, curr, count) {
        //             layer.close(layer.load(2));
        //         }
        //     })
        // }
        //价格调查-壳牌-数据展示
        // function  initTablePriceData() {
        //     tableInsPrice = febs.table.init({
        //         elem: '#tablePriceList',
        //         defaultToolbar: [],
        //         width: 500,
        //         cols: [[
        //             {field: 'optDate', title: '时间', templet: function (d) {
        //                     return '<div style="width: 200px">'+d.optDate+'</div>'
        //                 }},
        //             {field: 'oilCode', style: 'min-height: 200px', title: '油品',templet: function (d) {
        //                     var _html = '';
        //                     d.priceList.forEach(function (item) {
        //                         _html += '<div><text>'+item.oilCode+'</text></div>'
        //                     });
        //                     return _html
        //                 }},
        //             {field: 'price', style: 'min-height: 200px;', title: '价格',templet: function (d) {
        //                     var _html = '';
        //                     d.priceList.forEach(function (item) {
        //                         _html += '<div><text>'+item.price+'</text></div>'
        //                     });
        //                     return _html
        //                 }},
        //         ]],
        //         page: false,
        //         data: listPrice,
        //         done: function (res, curr, count) {
        //             layer.close(layer.load(2));
        //         }
        //     })
        // }
        //价格调查-竞争对手
        // function initTableC(params) {
        //     // 活动
        //     tableInsCom = febs.table.init({
        //         elem: '#tableCompetitors',
        //         // url: ctx + 'shellActivity/shellOilAllList',
        //         toolbar: '#toolbarDemoC',//开启头部工具栏，并为其绑定左侧模板
        //         defaultToolbar: [],
        //         where: params ? params : '',
        //         data: ajaxGet('shellActivity/shellOilAllList',params,1).listC,
        //         cols: [[
        //             {type: 'checkbox'},
        //             {field: 'shellName', title: '油站名称', minWidth: 200},
        //             {field: 'oilDate', title: '日期', minWidth: 180, event: 'date', data_field: "date"},
        //             {field: 'oil0', title: '0#柴油', minWidth: 50, edit: 'text'},
        //             {field: 'oil92', title: '92#汽油', minWidth: 50, edit: 'text'},
        //             {field: 'oil95', title: '95#汽油', minWidth: 50, edit: 'text'},
        //             {field: 'oil98', title: '98#汽油', minWidth: 50, edit: 'text'},
        //             {field: 'liveUrl', title: '图片地址', minWidth: 50, edit: 'text'},
        //             {field: '', title: '图片查看', minWidth: 50, event: 'img', templet:'#imgTpl'},
        //             {title: '操作', toolbar: '#dict-option', minWidth: 140},
        //             {field: 'remark', edit: 'text', templet: function (d) {
        //                     // var template = '<tr>' +
        //                     //     '<td colspan="10"><table id="tablePriceCompetitors" lay-filter="activityTable" lay-data="{id: \'tablePriceCompetitors\'}"></table></td>' +
        //                     //     '</tr>'
        //                     var _html = '', _list = '';
        //                     // console.log(d.createTimeList)
        //                     d.createTimeList.forEach(function (item) {
        //                         var _html1 = '', _list1 = '';
        //                         item.priceList.forEach(function (value) {
        //                             _list1 += '<div style="height: 28px;">' +
        //                                 '<text style="display: inline-block; width: 135px">'+value.oilCode+'</text>'+
        //                                 '<text style="display: inline-block; width: 135px">'+value.price+'</text>'+
        //                                 '</div>'
        //                             return
        //                         });
        //
        //                         _html1 += '<div style="width:500px;display: flex; align-items: center;justify-content: center">' +
        //                             '<div style="width: 166px">'+item.optDate+'</div>' +
        //                             '<div>' +
        //                             _list1+
        //                             '</div>'+
        //                             '</div><br>'
        //                         _html +=_html1;
        //                     });
        //                     var template = ''
        //                     return template
        //                 }}
        //         ]],
        //         page: false,
        //         done: function (res) {
        //             layer.close(layer.load(2));
        //         }
        //     })
        // }
        //价格调查-竞争对手-数据展示
        // function  initTablePriceComData() {
        //     tableInsPriceCom = febs.table.init({
        //         elem: '#tablePriceCompetitors',
        //         defaultToolbar: [],
        //         width: 500,
        //         cols: [[
        //             {field: 'optDate', title: '时间', templet: function (d) {
        //                     return '<div style="width: 200px">'+d.optDate+'</div>'
        //                 }},
        //             {field: 'oilCode', style: 'min-height: 200px', title: '油品',templet: function (d) {
        //                     var _html = '';
        //                     d.priceList.forEach(function (item) {
        //                         _html += '<div><text>'+item.oilCode+'</text></div>'
        //                     });
        //                     return _html
        //                 }},
        //             {field: 'price', style: 'min-height: 200px;', title: '价格',templet: function (d) {
        //                     var _html = '';
        //                     d.priceList.forEach(function (item) {
        //                         _html += '<div><text>'+item.price+'</text></div>'
        //                     });
        //                     return _html
        //                 }},
        //         ]],
        //         page: false,
        //         data: listPriceCom,
        //         done: function (res, curr, count) {
        //             layer.close(layer.load(2));
        //         }
        //     })
        // }
        //搜索框
        function getQueryParams() {
            return {
                shellId: $searchForm.find("select[name='shellSite']").val(),
                searchDate: $searchForm.find("input[name='searchDate']").val(),
                activityType: $searchForm.find("input[name='radioType']:checked").val()
            };
        }
        // 价格调查-市场促销 判断
        function isMarketFunc() {
            if (siteType == 1) {
                $('#shellPrice').css('display', 'none');
                $('#shellMarket').css('display', 'block');
            } else {
                $('#shellPrice').css('display', 'block');
                $('#shellMarket').css('display', 'none');
            }
        }
        //搜索-油站-请求
        function initDataSite() {
            febs.get(ctx + 'shellActivity/shellOilList', null, function (res) {
                if (res.code === 200) {
                    res.data.map(function (item,index) {
                        $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                    });
                    form.render('select');
                    return false;
                }
            })
        }
        //价格调查-请求
        function  ajaxGet(url,data,type) {
            var _list = [], _listC = [], _listContent = [], _listContentCom=[], _listPrice = [], _listPriceCom = [];
            $.ajax({
                type: 'GET',
                url: ctx + url,
                data: data,
                dataType: 'json',
                async : false,
                success: function (res) {
                    if (res.code == 200) {
                        tableDataFormat(res.data.rows);
                        $.each(res.data.rows, function (index,item) {
                            item.shellActivityOilList
                            if (item.type == 0) {
                                _list.push(item);
                                $.each(item.shellActivityOilDetailList, function (i,t) {
                                    _listContent.push(t)
                                })
                            } else {
                                _listC.push(item);
                                if (item.shellActivityOilDetailList) {
                                    $.each(item.shellActivityOilDetailList, function (i,t) {
                                        _listContentCom.push(t)
                                    })
                                }
                            }
                        });
                    } else {
                        febs.alert.error(res.message);
                        layer.close(layer.load(2));
                    }
                },
                error: function (res) {
                    febs.alert.error(res.message);
                }
            });
            $.each(_listContent, function (index,item) {
                if (item.weeks && item.weeks != '1') {
                    item.dateType = '分时';
                }  else {
                    item.dateType = '全时'
                }
            });
            $.each(_listContentCom, function (index,item) {
                if (item.weeks && item.weeks != '1') {
                    item.dateType = '分时';
                }  else {
                    item.dateType = '全时'
                }
            });
            listContent = _listContent;
            listContentCom = _listContentCom;

            //价格调查-数据展示-数据获取
            $.each(_list[0].shellActivityOilList, function (index, item) {
                if (item.price) {
                    var obj = {
                        optDate: item.optDate,
                        oilCode: item.oilCode,
                        price: item.price
                    };
                    _listPrice.push(obj)
                }
            });
            $.each(_listC, function (index, item) {
                $.each(item.shellActivityOilList, function (i,elem) {
                    if (elem.price) {
                        var obj = {
                            optDate: elem.optDate,
                            oilCode: elem.oilCode,
                            price: elem.price
                        };
                        _listPriceCom.push(obj)
                    }
                    item.createTimeList = refactoringPriceData(_listPriceCom)
                })
            });
            listPrice = refactoringPriceData(_listPrice);
            // console.log(listPrice)
            listPriceCom = refactoringPriceData(_listPriceCom);
            return obj ={
                list: _list,
                listC: _listC
            }
        }


        // 价格调查-数据展示-数据重构
        function refactoringPriceData(data) {
            var newData = [];
            data.forEach(function(item) {
                for (var i = 0; i < newData.length; i++) {
                    if (newData[i].optDate == item.optDate) {
                        newData[i].priceList.push({
                            optDate: item.optDate,
                            price: item.price,
                            oilCode: item.oilCode
                        });
                        return
                    }
                }
                newData.push({
                    optDate: item.optDate,
                    priceList: [{
                        optDate: item.optDate,
                        price: item.price,
                        oilCode: item.oilCode
                    }]
                })
            });
            if (newData.length > 3) {
                newData = newData.slice(-3)
            }
            return newData
        }
        // 市场促销-table-壳牌
        function initTableMarket (params) {
            localStorage.setItem('ShellActivityOilDetail', '');
            cleanShow();
            tableInsMarket = febs.table.init({
                elem: '#tableMarket',
                // url: ctx + 'shellActivity/shellOilAllList?activityType=1',
                toolbar: '#toolbarDemo',//开启头部工具栏，并为其绑定左侧模板
                defaultToolbar: [],
                where: params ? params : '',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'shellName', title: '油站名称', minWidth: 200},
                    {field: 'actDate', title: '日期', minWidth: 200, event: 'date',data_field: "date"},
                    {
                        field: 'oil0', title: '0#柴油', minWidth: 50, templet: function (d) {
                            var temp = '<button lay-event="saleOil0" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#0') {
                            //         temp = "<div lay-event='saleOil0'>"+ returnInfoHtml('#0',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {
                        field: 'oil92', title: '92#汽油', minWidth: 50, templet: function (d) {
                            var temp = '<button lay-event="saleOil92" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#92') {
                            //         temp = "<div lay-event='saleOil92'>"+ returnInfoHtml('#92',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {
                        field: 'oil95', title: '95#汽油', minWidth: 50,templet: function (d) {
                            var temp = '<button lay-event="saleOil95" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#95') {
                            //         temp = "<div lay-event='saleOil95'>"+ returnInfoHtml('#95',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {
                        field: 'oil98', title: '98#汽油', minWidth: 50, templet: function (d) {
                            var temp = '<button lay-event="saleOil98" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#98') {
                            //         temp = "<div lay-event='saleOil98'>"+ returnInfoHtml('#98',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {field: 'liveUrl', title: '图片地址', minWidth: 50, edit: 'text'},
                    {field: '', title: '图片查看', minWidth: 50, event: 'img', templet:'#imgTpl'},
                    {title: '操作', toolbar: '#dict-option', minWidth: 140},
                    {field: 'remark', edit: 'text', templet: function (d) {
                            var template = '<tr>' +
                                '<td colspan="10"><textarea style="width: 100%;height: 50px; border:1px solid #e5e5e5; border-radius: 5px; margin: 0 5px;">'+d.remark+ '</textarea></td>' +
                                '</tr>'
                            return template
                        }}
                ]],
                page: false,
                data: ajaxGet('shellActivity/shellOilAllList',params,0).list,
                done: function (res, curr, count) {
                    layer.close(layer.load(2));
                }
            })
        }

        // 市场促销-table-壳牌-数据展示
        function initTableMarketShow() {
            localStorage.setItem('ShellActivityOilDetail', '');
            cleanShow();
            tableInsMarketList = febs.table.init({
                elem: '#tableMarketList',
                // url: ctx + 'shellActivity/shellOilAllList',
                // toolbar: '#toolbarDemoC',//开启头部工具栏，并为其绑定左侧模板
                defaultToolbar: [],
                // where: params ? params : '',
                data: listContent,
                // data: ajaxGetA('shellActivity/shellOilAllListA',params,0).list,
                cols: [[
                    {field: 'oilCode', title: '油品', minWidth: 60},
                    {field: 'optDate', title: '调研时间', minWidth: 160, templet: function (d) {
                            if (d.optDate) {
                                return util.toDateString(d.optDate, "yyyy-MM-dd")
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'dateType', title: '时间类型', minWidth: 80},
                    {field: 'beginTime', title: '活动开始时间', minWidth: 160, templet: function (d) {
                            if (d.beginTime) {
                                return d.beginTime
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'endTime', title: '活动结束时间', minWidth: 160, templet: function (d) {
                            if (d.endTime) {
                                return d.endTime
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'weeks', title: '星期', minWidth: 100, templet: function (d) {
                            if (d.weeks) {
                                var _weeks = d.weeks.split(',');
                                for (var i = 0; i < _weeks.length; i++) {
                                    if (_weeks[i] == 'MON') {
                                        _weeks[i] = '周一'
                                    } else if (_weeks[i] == 'TUE') {
                                        _weeks[i] = '周二'
                                    } else if (_weeks[i] == 'WED') {
                                        _weeks[i] = '周三'
                                    } else if (_weeks[i] == 'THU') {
                                        _weeks[i] = '周四'
                                    } else if (_weeks[i] == 'FRI') {
                                        _weeks[i] = '周五'
                                    } else if (_weeks[i] == 'SAT') {
                                        _weeks[i] = '周六'
                                    } else if (_weeks[i] == 'SUN') {
                                        _weeks[i] = '周日'
                                    } else {
                                        _weeks[i] = ''
                                    }
                                }

                                _weeks = _weeks.toString();
                                return _weeks
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'consumerType', title: '顾客群体', minWidth: 100},
                    {field: 'activityUnit', title: '促销门槛单位', minWidth: 100},
                    {field: 'activityBase', title: '促销门槛', minWidth: 80},
                    {field: 'saleType', title: '折扣类型', minWidth: 100},
                    {field: 'salePrice', title: '折扣', minWidth: 60},
                    {field: 'activityCode', title: '特殊活动编码', minWidth: 100,templet: function (d) {
                            if (d.activityCode) {
                                var _name = '';
                                $.each(activityZyData,function (index,item) {
                                    if (d.activityCode == item.value) {
                                        _name = item.name
                                    }
                                })
                                return _name
                            } else {
                                return d.activityCode
                            }

                        }},
                    {field: 'activityValue', title: '特殊活动值', minWidth: 100},
                    {field: 'id', title: '操作', minWidth: 50, event: 'actDel', templet:'#actDel'}
                ]],
                page: false,
                done: function (res) {
                    layer.close(layer.load(2));
                }
            })
        }
        //市场促销-table-竞争对手
        function initTableMarketCom (params) {
            tableInsMarketCom = febs.table.init({
                elem: '#tableMarketCom',
                // url: ctx + 'shellActivity/shellOilAllList?activityType=1',
                toolbar: '#toolbarDemoC',//开启头部工具栏，并为其绑定左侧模板
                defaultToolbar: [],
                where: params ? params : '',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'shellName', title: '油站名称', minWidth: 200},
                    {field: 'actDate', title: '日期', minWidth: 200, event: 'date', data_field: "date"},
                    {
                        field: 'oil0', title: '0#柴油', minWidth: 50, edit: 'text', templet: function (d) {

                            var temp = '<button lay-event="saleOil0" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#0') {
                            //         temp = "<div lay-event='saleOil0'>"+ returnInfoHtml('#0',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {
                        field: 'oil92', title: '92#汽油', minWidth: 50, edit: 'text', templet: function (d) {
                            var temp = '<button lay-event="saleOil92" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#92') {
                            //         temp = "<div lay-event='saleOil92'>"+ returnInfoHtml('#92',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {
                        field: 'oil95', title: '95#汽油', minWidth: 50, edit: 'text', templet: function (d) {
                            var temp = '<button lay-event="saleOil95" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#95') {
                            //         temp = "<div lay-event='saleOil95'>"+ returnInfoHtml('#0',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {
                        field: 'oil98', title: '98#汽油', minWidth: 50, edit: 'text', templet: function (d) {
                            var temp = '<button lay-event="saleOil98" type="button" class="layui-btn layui-btn-xs"><i class="layui-icon">&#xe654;</i></button>'
                            // $.each(d.shellActivityOilDetailList, function (index, item) {
                            //     if (item.oilCode == '#98') {
                            //         temp = "<div lay-event='saleOil98'>"+ returnInfoHtml('#98',d.shellActivityOilDetailList) + "</div>"
                            //     }
                            // });
                            return temp
                        }
                    },
                    {field: 'liveUrl', title: '图片地址', minWidth: 50, edit: 'text'},
                    {field: '', title: '图片查看', minWidth: 50, event: 'img', templet:'#imgTpl'},
                    {title: '操作', toolbar: '#dict-option', minWidth: 140},
                    {field: 'remark', edit: 'text', templet: function (d) {
                            var template = '<tr>' +
                                '<td colspan="10"><textarea style="width: 100%;height: 50px; border:1px solid #e5e5e5; border-radius: 5px; margin: 0 5px;">'+d.remark+ '</textarea></td>' +
                                '</tr>'
                            return template
                        }}
                ]],
                page: false,
                data:ajaxGet('shellActivity/shellOilAllList',params,0).listC,
                done: function (res, curr, count) {
                    layer.close(layer.load(2));
                }
            })
        }
        function initTableMarketComShow() {
            tableInsMarketListCom = febs.table.init({
                elem: '#tableMarketListCom',
                // url: ctx + 'shellActivity/shellOilAllList',
                // toolbar: '#toolbarDemoC',//开启头部工具栏，并为其绑定左侧模板
                defaultToolbar: [],
                // where: params ? params : '',
                data: listContentCom,
                cols: [[
                    {field: 'shellName', title: '油站名称', minWidth: 100},
                    {field: 'oilCode', title: '油品', minWidth: 60},
                    {field: 'optDate', title: '调研时间', minWidth: 160, templet: function (d) {
                            if (d.optDate) {
                                return util.toDateString(d.optDate, "yyyy-MM-dd")
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'dateType', title: '时间类型', minWidth: 80},
                    {field: 'beginTime', title: '活动开始时间', minWidth: 160, templet: function (d) {
                            if (d.beginTime) {
                                return d.beginTime
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'endTime', title: '活动结束时间', minWidth: 160, templet: function (d) {
                            if (d.endTime) {
                                return d.endTime
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'weeks', title: '星期', minWidth: 100, templet: function (d) {
                            if (d.weeks) {
                                var _weeks = d.weeks.split(',');
                                for (var i = 0; i < _weeks.length; i++) {
                                    if (_weeks[i] == 'MON') {
                                        _weeks[i] = '周一'
                                    } else if (_weeks[i] == 'TUE') {
                                        _weeks[i] = '周二'
                                    } else if (_weeks[i] == 'WED') {
                                        _weeks[i] = '周三'
                                    } else if (_weeks[i] == 'THU') {
                                        _weeks[i] = '周四'
                                    } else if (_weeks[i] == 'FRI') {
                                        _weeks[i] = '周五'
                                    } else if (_weeks[i] == 'SAT') {
                                        _weeks[i] = '周六'
                                    } else if (_weeks[i] == 'SUN') {
                                        _weeks[i] = '周日'
                                    } else {
                                        _weeks[i] = ''
                                    }
                                }

                                _weeks = _weeks.toString();
                                return _weeks
                            } else {
                                return '——'
                            }
                        }},
                    {field: 'consumerType', title: '顾客群体', minWidth: 100},
                    {field: 'activityUnit', title: '促销门槛单位', minWidth: 100},
                    {field: 'activityBase', title: '促销门槛', minWidth: 80},
                    {field: 'saleType', title: '折扣类型', minWidth: 100},
                    {field: 'salePrice', title: '折扣', minWidth: 60},
                    {field: 'activityCode', title: '特殊活动编码', minWidth: 100,templet: function (d) {
                            if (d.activityCode) {
                                var _name = '';
                                $.each(activityJzData,function (index,item) {
                                    if (d.activityCode == item.value) {
                                        _name = item.name
                                    }
                                })
                                return _name
                            } else {
                                return d.activityCode
                            }

                        }},
                    {field: 'activityValue', title: '特殊活动值', minWidth: 100},
                    {field: 'id', title: '操作', minWidth: 50, event: 'actDel', templet:'#actDel'}
                ]],
                page: false,
                done: function (res) {
                    layer.close(layer.load(2));
                }
            })
        }
        // 特殊-自营
        function activityZySelect() {
            febs.get(ctx + 'shellActivity/shellActivityDicList', {'type': '0'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.activityCode,
                            name: item.activityName,
                            inputValue: item.activityValue
                        })
                    });
                    activityZyData = _data;
                }
            })
        }
        // 特殊-竞争
        function activityJzSelect() {
            febs.get(ctx + 'shellActivity/shellActivityDicList', {'type': '1'}, function (res) {
                if (res.code === 200) {
                    var _data = [];
                    res.data.map(function (item,index) {
                        // $('#siteSelect').append(new Option(item.siteName, item.siteid));// 下拉菜单里添加元素
                        _data.push({
                            value: item.activityCode,
                            name: item.activityName,
                            inputValue: item.activityValue
                        })
                    });
                    activityJzData = _data;
                }
            })
        }
        // 数据格式化
        function tableDataFormat(data) {
            $.each(data, function (index, item) {
                $.each(item.shellActivityOilList, function (i, elm) {
                    if (elm.oilCode == '#0') {
                        item.oil0 = elm.price
                    } else if (elm.oilCode == '#92') {
                        item.oil92 = elm.price
                    } else  if (elm.oilCode == '#95') {
                        item.oil95 = elm.price
                    } else if (elm.oilCode == '#98') {
                        item.oil98 = elm.price
                    } else {}
                })
            })
        }
        // 油号数据处理
        function oilDataFormat(type, data) {
            var _oilType = '', _detailArr = [];
            switch (type) {
                case 'saleOil0':
                    _oilType = '#0';
                    break;
                case 'saleOil92':
                    _oilType = '#92';
                    break;
                case 'saleOil95':
                    _oilType = '#95';
                    break;
                default:
                    _oilType = '#98';
                    break;
            }
            $.each(data.shellActivityOilDetailList, function (index, item) {
                if (_oilType == item.oilCode) {
                    _detailArr.push(item)
                }
            });
            data.shellActivityOilDetailList = _detailArr;
            return data;
        }
        // 添加后 - 详情模版
        function returnInfoHtml(type,data) {
            var _list =[], _html='';
            if (shellActivityOilDetailList) {
                _list = JSON.parse(shellActivityOilDetailList)
            } else {
                _list = data
            }
            $.each(_list, function (index,item) {
                if (item.oilCode = type) {
                    if (item.weeks) {
                        _html += "<p>分时</p><span>"+item.weeks+'&nbsp;'+item.beginTime+ "-" +item.endTime + "</span>" +
                            "<div>"+ item.salePrice + item.saleType + '=' + item.activityBase + item.saleType +"</div>"
                    } else {
                        _html += "<div><p>全时</p>"+ item.salePrice + item.saleType + '=' + item.activityBase + item.saleType +"</div>";
                    }
                }
            });
            return _html
        }
        //   供给-子页面调用方法
        var _tools = {
            reloadTable: function () {
                tableInsMarket.reload();
                tableInsMarketCom.reload();
                backShow()
            }

        };
        window.tools = _tools
        //回写数据更新
        function backShow() {
            var currentList = [],dList = localStorage.getItem('ShellActivityOilDetail');
            cleanShow();
            if (dList) {
                currentList=JSON.parse(dList);
                var _html = ''
                var ttype=currentList[0].type;
                // console.log(currentList)
                currentList.forEach(function (item) {
                    var beginTime='---';
                    if(item.beginTime!=null){
                        beginTime=item.beginTime;
                    }
                    var endTime='---';
                    if(item.endTime!=null){
                        endTime=item.endTime;
                    }
                    var weeks='---';
                    if(item.weeks!=null){
                        weeks=item.weeks;
                    }
                    var _html1 = '';
                    _html1 += '<tr data-index="0" class="">' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.oilCode+'</div></td>' +
                        '<td  data-minwidth="160" class=""><div class="layui-table-cell">'+beginTime+'</div></td>' +
                        '<td  data-minwidth="160" class=""><div class="layui-table-cell">'+endTime+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+weeks+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.consumerType+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.activityUnit+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.activityValue+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.saleType+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.salePrice+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.activityCode+'</div></td>' +
                        '<td  data-minwidth="60" class=""><div class="layui-table-cell">'+item.activityValue+'</div></td>' +
                        '</tr>'
                    _html +=_html1;
                });
                if(ttype=="0"){
                    $(_html).appendTo($('#tableAc tbody:last'));
                }else{
                    $(_html).appendTo($('#tableBc tbody:last'));
                }
            }
        }
        //table 数据清空
        function cleanShow(){
            // $('.tableAc tr').remove()
            // $('.tableBc tr').remove()
            $("#tableAc tbody").html("");
            $("#tableBc tbody").html("");
        }
    })
</script>